//
//  CampusDetailImagePreviewCell.m
//  ShowYork
//
//  Created by hxh on 2021/3/26.
//  Copyright © 2021 hxh. All rights reserved.
//

#import "CampusDetailImagePreviewCell.h"
#import "CapusDetailPictureView.h"
#import "CampusSchoolPictureItemModel.h"
@interface CampusDetailImagePreviewCell ()
@property (nonatomic,strong)CapusDetailPictureView *picView;
@property (nonatomic,copy)NSArray *dataArray;
@property (nonatomic,assign)NSInteger maxCount;
@end

@implementation CampusDetailImagePreviewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self setUI];
    }
    
    return self;
}
- (void)setUI{
    self.picView = [[CapusDetailPictureView alloc]init];
    [self.contentView addSubview:self.picView];
    
    [self.picView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.equalTo(self.contentView).offset(20);
        make.bottom.right.equalTo(self.contentView).offset(-20);
        make.height.mas_equalTo((kScreenW - 40) * (165.0f/337.0f)).priorityHigh();
    }];
    __weak typeof(self)weakSelf = self;
    self.picView.done = ^(NSInteger index) {
        
        if (weakSelf.delegate && [weakSelf.delegate respondsToSelector:@selector(showMorePicture)]) {
            if (index == 4 && weakSelf.maxCount > 5) {
                [weakSelf.delegate showMorePicture];
            }else{
                [weakSelf.delegate showTargetPictureAtIndex:index];
            }
        }
    };
}
+(instancetype)cellWithTableView:(UITableView *)tableView{
    NSString *ID = @"CampusDetailImagePreviewCell";
    CampusDetailImagePreviewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (!cell) {
        cell = [[CampusDetailImagePreviewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return cell;
}
- (void)setPictureList:(NSArray *)pictureList maxCount:(NSNumber *)maxCount{
    self.dataArray = pictureList;
    
    NSMutableArray *urls = [NSMutableArray array];
    [pictureList enumerateObjectsUsingBlock:^(CampusSchoolPictureItemModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        [urls addObject:obj.cover];
    }];
    
    self.maxCount = maxCount.intValue;
    
    [self.picView setIndex:maxCount urls:urls];
    

}
@end
